You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by shadman <sh...@att.com> on 2007/05/21 21:48:20 UTC

[S2] form population problem

I can't seem to get values retrieved from the DB to populate on the form. The
list jsp and retrieving from DB work great, but values don't seem to make it
to the jsp. I pass the ID into the action method, retrieve the record, and
want to display the results.

struts.xml:
   <action name="findDeptId" class="actions.DepartmentAction"
method="findById">
         <result name="input">jsps/errors.jsp</result>
         <result name="success">jsps/edit_dept.jsp</result>
         <interceptor-ref name="crudStack"/>
   </action>

DepartmentAction:
	public String findById () throws Exception {
		this.dept = getDaoManager().getDeptDao().findById(this.getId());
		return SUCCESS;
	}

Method fills dept object. also, getDept() & setDept() in action.

edit_dept.jsp:
  <s:form action="save" validate="true" >
   <table cellspacing="0" cellpadding="0" border="0">
   <tr>
      <td align="right">ID:</td>
      <td>
         <s:property value="dept.deptId" />
         <s:hidden name="dept.deptId" value="dept.deptName" />
      </td>
   </tr><tr>
     <s:textfield name="dept.deptName" label="Dept Name"
value="dept.deptName" size="10" /> 
   </tr>
   </table>
   </s:form>

I have to be doing something simple wrong, I just don't see it.
shadman
-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10725666
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by shadman <sh...@att.com>.
btw, Dave, to answer a couple of your q's below:

>> <s:textfield name="dept.deptName" 
>>              label="Dept Name"
>>              value="dept.deptName" 
>>              size="10" /> 

>If dept (the Department) is already loaded then the
>value="dept.deptName" is not necessary; bean values
>will be handled automagically... I don't know if this
>is the problem, but as another response hinted at, I'd
>remove it.

Dropping the value does not seem to work - I get a blank field (but then I
may not have the "bean" right). And I would expected that to occur, even
though I've read what you're referring to. The above should look like this:
<s:textfield name="dept.deptName" label="Dept Name" value="%{dept.deptName}"
/> 

>Just out of curiosity, what happens if you put an
><s:property value="dept"/> in the JSP? You should get
>a default Java toString (unless you've overridden it
>:)
I get this as output:
com.att.etpi.eval.struts2.hibernate.Department@1d318f
basically, what I'd expect - a reference to the obj.

So, as far as the beer goes, I agree. I do owe you one though ...

shadman

-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10764939
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by Dave Newton <ne...@yahoo.com>.
--- shadman <sh...@att.com> wrote:
> I am more than just a little embarrassed.

I think if we all had a nickel for each time we've
made a mistake like that and had it staring us in the
face for a day or two we could buy enough beer to at
least make us not care that we made a mistake like
that and had it staring us in the face for a day or
two ;)

d.



       
____________________________________________________________________________________Yahoo! oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by shadman <sh...@att.com>.
Thanks once again, Dave.  I am more than just a little embarrassed.  Seems I
focused too much on S2, instead of core Java (auto-gen can be a bad thing
sometimes).  "private" was the problem.  Such a freshman error ...

shadman


--- shadman <sh...@att.com> wrote:
> 	private Department getDept() { return dept; }
> 	private void setDept(Department department) {

*dingdingding*

Private, huh? 

;)


-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10764090
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by Dave Newton <ne...@yahoo.com>.
--- shadman <sh...@att.com> wrote:
> 	private Department getDept() { return dept; }
> 	private void setDept(Department department) {

*dingdingding*

Private, huh? 

;)

> <s:textfield name="dept.deptName" 
>              label="Dept Name"
>              value="dept.deptName" 
>              size="10" /> 

If dept (the Department) is already loaded then the
value="dept.deptName" is not necessary; bean values
will be handled automagically... I don't know if this
is the problem, but as another response hinted at, I'd
remove it.

Just out of curiosity, what happens if you put an
<s:property value="dept"/> in the JSP? You should get
a default Java toString (unless you've overridden it
:)

> Is the  id="save_dept_deptName" correct?

Yes; the id attribute is created from the form action
and the field name, AFAICT.

> Can you see anything that I'm doing wrong? 

Unfortunately I still don't :/

d.



 
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check. 
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by shadman <sh...@att.com>.
Thanks for the reply, Dave. So I have the following:

struts2test1.xml
   <action name="findDeptId"
class="com.att.etpi.eval.struts2.actions.DepartmentAction">
        <result name="input">jsps/edit_list.jsp</result>
        <result name="success">jsps/edit_dept.jsp</result>
        <interceptor-ref name="crudStack"/>
   </action>

Java:
public class Department implements java.io.Serializable {
    private short deptId;
    private String deptName;

    public Department() { }
    public short getDeptId() { return this.deptId; }
    public void setDeptId(short deptId) { this.deptId = deptId; }
    public String getDeptName() { return this.deptName; }
    public void setDeptName(String deptName) { this.deptName = deptName;}
}

public class DepartmentAction extends ActionSupport 
                                         implements Preparable,
ParameterAware
{
	public String execute () throws Exception {
		this.dept = getDaoManager().getDeptDao().findById(this.getId());
		return SUCCESS;
	}
	private Department getDept() { return dept; }
	private void setDept(Department department) { this.dept = department; }
}

edit_dept.jsp:
  <s:form action="save" validate="true" namespace="/struts2test1" >
   <table>
   <tr>
      <td align="right">&nbsp;ID:&nbsp;</td>
      <td>
         <s:property value="dept.deptId" />/3:
      </td>
   </tr><tr>
     <s:textfield name="dept.deptName" label="Dept Name"
value="dept.deptName" size="10" /> 
   </tr>
   </table>
   </s:form>

For textfield:
<s:textfield name="deptName" label="Dept Name" value="dept.deptName" />

HTML produced is: 
<td class="tdLabel"><label for="save_deptName" class="label">Dept
Name:</label></td>
<td><input type="text" name="deptName" value="dept.deptName"
id="save_deptName"/>
</td>

For textfield:
<s:textfield name="dept.deptName" label="Dept Name" value="dept.deptName" />

Produces:
<td class="tdLabel"><label for="save_dept_deptName" class="label">Dept
Name:</label></td>
<td><input type="text" name="dept.deptName" value="dept.deptName"
id="save_dept_deptName"/>
</td>

None of this works, unless I break the domain object out in the action.  Is
the  id="save_dept_deptName" correct?  Can you see anything that I'm doing
wrong? 

thanks once again for your time and help, 
shadman



Dave Newton-4 wrote:
> 
> --- shadman <sh...@att.com> wrote:
>> The DepartmentAction retrieves the dept object from
>> DB, and has getters and setters for the domain
> "dept"
>> object in the action.
>> 
>> <s:property value="dept.deptId" />
> 
> This is the proper syntax; I do it all over the place.
> 
> If the action has a getDept() and the dept has a
> getDeptId(), and you are dispatching to the result
> (not redirecting), then it should work as you have it.
> 
> I'd first re-check the flow to the result JSP, then
> check to make sure the objects are following JavaBean
> conventions...
> 
> In short, all the stuff you've probably already done
> ;)
> 
> But I'd do it again anyway :/
> 
> d.
> 
> 
> 
>        
> ____________________________________________________________________________________Looking
> for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
> http://farechase.yahoo.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10745388
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by Dave Newton <ne...@yahoo.com>.
--- shadman <sh...@att.com> wrote:
> The DepartmentAction retrieves the dept object from
> DB, and has getters and setters for the domain
"dept"
> object in the action.
> 
> <s:property value="dept.deptId" />

This is the proper syntax; I do it all over the place.

If the action has a getDept() and the dept has a
getDeptId(), and you are dispatching to the result
(not redirecting), then it should work as you have it.

I'd first re-check the flow to the result JSP, then
check to make sure the objects are following JavaBean
conventions...

In short, all the stuff you've probably already done
;)

But I'd do it again anyway :/

d.



       
____________________________________________________________________________________Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
http://farechase.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by shadman <sh...@att.com>.
Thanks for the reply, Jeromy. That is exactly what has not been working.
Unfortunately, the s:property does not work either.

"dept" is a Department domain object, with two field, deptId: short; and
deptName: String. Both have getters and setters.

The DepartmentAction retrieves the dept object from DB, and has getters and
setters for the domain "dept" object in the action.

I tried:
<s:property value="dept.deptId" />
<s:property value="%{dept.deptId}" /> 
(as well as a bunch of other things which shouldn't work, and don't)

But this does not work, and I think it should, from what the documentation
says. I can see the Action and the "dept" object on the stack in the Eclipse
debugger. When I created a deptId var, and create a getter and setter for it
in the Action, and do this:
<s:property value="deptId" />

This works just fine, but I shouldn't have to break the domain object out in
the Action, right?

(I don't have a struts.properties file set up, 'cause the default as you
said is enabled.)

This is all fundamental to struts2, so I've got to be doing something
stupid, right?

thanks, shadman


Jeromy Evans - Blue Sky Minds wrote:
> 
> I'm not 100% sure of your intent as this line is a bit strange - trying 
> to set the deptId to the deptName
> 
>          <s:hidden name="dept.deptId" value="dept.deptName" />
> 
> but anyway, the documentation on the wiki around the expressions for 
> some tags is a bit confusing and I suspect the problem is that you need 
> "%{ }" to explicitly identify the OGNL expression for the 'value' 
> attributes of s:hidden and s:textfield (but NOT for the 'value' 
> attribute of s:property). 
> 
> ie.
> 
> <s:form action="save" validate="true" >
>    <table cellspacing="0" cellpadding="0" border="0">
>    <tr>
>       <td align="right">ID:</td>
>       <td>
>          <s:property value="dept.deptId" />
>          <s:hidden name="dept.deptId" value="%{dept.deptName}" />
>       </td>
>    </tr><tr>
>      <s:textfield name="dept.deptName" label="Dept Name"
> value="%{dept.deptName}" size="10" /> 
>    </tr>
>    </table>
>    </s:form>
> 
> I'm assuming your s:property is working.  Contrary to what's stated on 
> http://struts.apache.org/2.x/docs/tag-syntax.html, the 'value' attribute 
> is not parsed as an expression.  Having to include %{} is called "Alt 
> Syntax" and this mode is enabled by default.
> 
> This is an extract from default.properties:
> ### use alternative syntax that requires %{} in most places
> ### to evaluate expressions for String attributes for tags
> struts.tag.altSyntax=true
> 
> regards,
>  Jeromy Evans
> 
> shadman wrote:
>> So, if the action properties are pushed onto the stack via OGNL, then
>> what
>> from below would be preventing me from seeing the values that should be
>> there? Displaying a list worked just find, the Dept object seems to be
>> unavailable. I have getter and setter, according to documentation, I
>> shouldn't have to do anything else. According to examples, what I show
>> below
>> would seem to be correct. Appreciate the help.
>>
>> Thanks, shadman
>>
>>
>> shadman wrote:
>>   
>>> I can't seem to get values retrieved from the DB to populate on the
>>> form.
>>> The list jsp and retrieving from DB work great, but values don't seem to
>>> make it to the jsp. I pass the ID into the action method, retrieve the
>>> record, and want to display the results.
>>>
>>> struts.xml:
>>>    <action name="findDeptId" class="actions.DepartmentAction"
>>> method="findById">
>>>          <result name="input">jsps/errors.jsp</result>
>>>          <result name="success">jsps/edit_dept.jsp</result>
>>>          <interceptor-ref name="crudStack"/>
>>>    </action>
>>>
>>> DepartmentAction:
>>> 	public String findById () throws Exception {
>>> 		this.dept = getDaoManager().getDeptDao().findById(this.getId());
>>> 		return SUCCESS;
>>> 	}
>>>
>>> Method fills dept object. also, getDept() & setDept() in action.
>>>
>>> edit_dept.jsp:
>>>   <s:form action="save" validate="true" >
>>>    <table cellspacing="0" cellpadding="0" border="0">
>>>    <tr>
>>>       <td align="right">ID:</td>
>>>       <td>
>>>          <s:property value="dept.deptId" />
>>>          <s:hidden name="dept.deptId" value="dept.deptName" />
>>>       </td>
>>>    </tr><tr>
>>>      <s:textfield name="dept.deptName" label="Dept Name"
>>> value="dept.deptName" size="10" /> 
>>>    </tr>
>>>    </table>
>>>    </s:form>
>>>
>>> I have to be doing something simple wrong, I just don't see it.
>>> shadman
>>>
>>>     
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10742001
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
I'm not 100% sure of your intent as this line is a bit strange - trying 
to set the deptId to the deptName

         <s:hidden name="dept.deptId" value="dept.deptName" />

but anyway, the documentation on the wiki around the expressions for 
some tags is a bit confusing and I suspect the problem is that you need 
"%{ }" to explicitly identify the OGNL expression for the 'value' 
attributes of s:hidden and s:textfield (but NOT for the 'value' 
attribute of s:property). 

ie.

<s:form action="save" validate="true" >
   <table cellspacing="0" cellpadding="0" border="0">
   <tr>
      <td align="right">ID:</td>
      <td>
         <s:property value="dept.deptId" />
         <s:hidden name="dept.deptId" value="%{dept.deptName}" />
      </td>
   </tr><tr>
     <s:textfield name="dept.deptName" label="Dept Name" value="%{dept.deptName}" size="10" /> 
   </tr>
   </table>
   </s:form>

I'm assuming your s:property is working.  Contrary to what's stated on 
http://struts.apache.org/2.x/docs/tag-syntax.html, the 'value' attribute 
is not parsed as an expression.  Having to include %{} is called "Alt 
Syntax" and this mode is enabled by default.

This is an extract from default.properties:
### use alternative syntax that requires %{} in most places
### to evaluate expressions for String attributes for tags
struts.tag.altSyntax=true

regards,
 Jeromy Evans

shadman wrote:
> So, if the action properties are pushed onto the stack via OGNL, then what
> from below would be preventing me from seeing the values that should be
> there? Displaying a list worked just find, the Dept object seems to be
> unavailable. I have getter and setter, according to documentation, I
> shouldn't have to do anything else. According to examples, what I show below
> would seem to be correct. Appreciate the help.
>
> Thanks, shadman
>
>
> shadman wrote:
>   
>> I can't seem to get values retrieved from the DB to populate on the form.
>> The list jsp and retrieving from DB work great, but values don't seem to
>> make it to the jsp. I pass the ID into the action method, retrieve the
>> record, and want to display the results.
>>
>> struts.xml:
>>    <action name="findDeptId" class="actions.DepartmentAction"
>> method="findById">
>>          <result name="input">jsps/errors.jsp</result>
>>          <result name="success">jsps/edit_dept.jsp</result>
>>          <interceptor-ref name="crudStack"/>
>>    </action>
>>
>> DepartmentAction:
>> 	public String findById () throws Exception {
>> 		this.dept = getDaoManager().getDeptDao().findById(this.getId());
>> 		return SUCCESS;
>> 	}
>>
>> Method fills dept object. also, getDept() & setDept() in action.
>>
>> edit_dept.jsp:
>>   <s:form action="save" validate="true" >
>>    <table cellspacing="0" cellpadding="0" border="0">
>>    <tr>
>>       <td align="right">ID:</td>
>>       <td>
>>          <s:property value="dept.deptId" />
>>          <s:hidden name="dept.deptId" value="dept.deptName" />
>>       </td>
>>    </tr><tr>
>>      <s:textfield name="dept.deptName" label="Dept Name"
>> value="dept.deptName" size="10" /> 
>>    </tr>
>>    </table>
>>    </s:form>
>>
>> I have to be doing something simple wrong, I just don't see it.
>> shadman
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] form population problem

Posted by shadman <sh...@att.com>.
So, if the action properties are pushed onto the stack via OGNL, then what
from below would be preventing me from seeing the values that should be
there? Displaying a list worked just find, the Dept object seems to be
unavailable. I have getter and setter, according to documentation, I
shouldn't have to do anything else. According to examples, what I show below
would seem to be correct. Appreciate the help.

Thanks, shadman


shadman wrote:
> 
> I can't seem to get values retrieved from the DB to populate on the form.
> The list jsp and retrieving from DB work great, but values don't seem to
> make it to the jsp. I pass the ID into the action method, retrieve the
> record, and want to display the results.
> 
> struts.xml:
>    <action name="findDeptId" class="actions.DepartmentAction"
> method="findById">
>          <result name="input">jsps/errors.jsp</result>
>          <result name="success">jsps/edit_dept.jsp</result>
>          <interceptor-ref name="crudStack"/>
>    </action>
> 
> DepartmentAction:
> 	public String findById () throws Exception {
> 		this.dept = getDaoManager().getDeptDao().findById(this.getId());
> 		return SUCCESS;
> 	}
> 
> Method fills dept object. also, getDept() & setDept() in action.
> 
> edit_dept.jsp:
>   <s:form action="save" validate="true" >
>    <table cellspacing="0" cellpadding="0" border="0">
>    <tr>
>       <td align="right">ID:</td>
>       <td>
>          <s:property value="dept.deptId" />
>          <s:hidden name="dept.deptId" value="dept.deptName" />
>       </td>
>    </tr><tr>
>      <s:textfield name="dept.deptName" label="Dept Name"
> value="dept.deptName" size="10" /> 
>    </tr>
>    </table>
>    </s:form>
> 
> I have to be doing something simple wrong, I just don't see it.
> shadman
> 

-- 
View this message in context: http://www.nabble.com/-S2--form-population-problem-tf3792422.html#a10737881
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org