Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Unable To Pass A Hidden Field To scaffold.ProcessAction

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass two hidden fields; username and keyName from a JSP via a SUBMIT button:

and an action mapping:

How come the username is not passed to the FindEditorData.java while the keyName is successfully passed. In the browser, I got:
name=null; kn=journal_category; kv=null
The code of my FindEditorData is shown below:
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
check the syntax of JSP, i think it should be
<%= username %>
 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason for this is that the struts tag html:hidden does not know how to process your jsp tag <%= and hence you are getting a null value. If you want the value of your username field in the hidden parameter, either use all html <input type="hidden".....
or use struts with jstl
<c:set var = "user">
<bean:write property="username" name="formbeanname"/>
</c:set>
and then
<html:hidden property="username" value="<c ut value="${user}"/>">
This will solve your problem. Its all about mixing and matching and putting stuff in the right context.
Sahil
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Udaya. I have tried <%= username %> instead <%=username%>. It does not work. I still cannot pass 'username' to the scaffold.ProcessAction class. I have also checked that it is 'username' not 'userName'. I did not mess up uppercase and lowercase.
Hi, Sandy. The <html:hidden ....> tag is recognized by the Struts. In my JSP, I try to pass two hidden fields. One is passed to the ProcessAction class successfully, but the other failed.
Oh! I have searched my head and cannot figure out what is wrong. Here is my JSP again:
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two questions:
1. When your HTML is displayed and you do a "View->Source" in your browser, does the field correctly display with the username?
2. Does your ActionForm have a "username" property?
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to answer your first question. I use Struts tile. When my JSP (not HTML) is displayed in the browser, the right mouse click "View Source" does not show the "definition".
I do not have an ActionForm. The Java class FindEditorData.java extends Bean.java. The 'username' is one of the properties in the Bean.java. If username was not defined by a pair of get/set methods in the Bean.java, I would have a compilation error saying "cannot resolve symbol: getUsername();" in the FindEditorData.java.
I passed two hidden fields from my JSP at the same time. One of the hidden field is passed and with correct value. The other one 'username' is passed but its value is a null. There must be a valid value for the 'username' in my JPS because before reaching the following step, a user has been successfully logged in with a valid name:

My action mapping is like:

and the code of the FindEditorData.java is shown below:
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by JiaPei Jen:
I am unable to answer your first question. I use Struts tile. When my JSP (not HTML) is displayed in the browser, the right mouse click "View Source" does not show the "definition".


When you run your application and view the page with the form, select View->Source. There should be a line in the source HTML which says something like:
<input type="hidden" name="username" value="???">
What shows up for value? Whether you are using tiles, jsp, asp, php, or whatever, the above will work. And if you're using frames for some reason, simply right-click in the correct fram and select "View Source".

I do not have an ActionForm.


Your ActionMapping refers to an ActionForm called "articelForm".
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have posted many messages on the Forum. My total postings at the JavaRanch are more than 800. Do I sound like feeding a troll? Or I am simply discussing my problem? My postings are viewed by all the visitors. Let them be the judge. I think the sentence "do not feed a troll" is an attack. I would like the Moderator of the Forum to intervene.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies. "Please Don't Feed the Troll" is my sig line, and is not directed at you or anyone else for that matter. However, as it appears there may some misunderstandings in this regard, I will change it.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading your explanation, I went back to read the postings again. I could see where my misunderstanding was from. Okay, I agree on that there is no issue. All of us have been discussing Java problems.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you have mentioned, I, too, suspected that the statement in my JSP:
request.getRemoteUser();
returns nothing. Therefore, I did a test in my JSP. In addition to request.getRemoteUser(); I created another String manually:

And the browser shows:
The user name is: Gloria Jen. The role is: author.
Gloria Jen is the name that I provided while logging on and authenticated by the container. Therefore, the request.getRemoteUser(); does not return a null. And I hope that it means I am not passing a null value when I use the hidden field technique.
Then, I pass two hidden fields (with value in them) from my JSP to a Java class (FindEditorData.java), which is of scaffold.ProcessAction type. One of the field is passed with its value correctly retrieved. The other field is passed with its value found to be null.
What could go wrong? I have been thinking about it for days and so do those who try to help me.
 
I want my playground back. Here, I'll give you this tiny ad for it:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic