You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stuart Guthrie <sf...@eurekait.com> on 2004/08/16 16:01:49 UTC

html:text - want to set disable= to a bean value

Hi there, 

What I'm trying to do is re-use the same jsp for ADD/UPDATE modes. In
order to do this, certain field attributes will be different depending
on the modes and sometimes even on the user's security credentials or
the 'status' of the customer row.

To this end I need to pass in the form bean whether a particular field
is disabled or not

I've searched the archives to no avail. I'm trying to set the disable=''
attribute on the html:text tag to a value in the form bean I'm passing
in.

eg:

formbean.isCustomerCodeEnabled()

returns a boolean true/false

formbean.getCustomerCode()

is the value of customer code.

I'm trying (hoping) to do something like this:

<html:text property="customerCode" maxlength="8"size="8" 
disable="!CustomerCodeEnabled"  />

I've tried lots of different approaches, all failing. I've also scanned
the examples to no avail.

Latest attempt is:

<bean:define id="customerCodeEnabled"
name="CustomerFormWindowMainTabActionForm"
property="CustomerCodeEnabled"
    type="boolean" value="true"/>

<% boolean customerCodeDisabled=(!customerCodeEnabled); %>
<TD><html:text property="customerCode" maxlength="8"size="8" 
disabled="<%=customerCodeDisabled%>"  /></TD>

Which fails with:

customerCodeEnabled = null; [javac] ^ An error occurred at line: 87 in
the jsp file: /CustomerFormWindowMainTabBody.jsp Generated servlet
error:
[javac]/home/sfg/javadev/jboss-3.2.3/server/default/work/MainEngine/localhost/pimsweb/CustomerFormWindowMainTabBody_jsp.java:175: inconvertible types 
[javac] found : java.lang.Object [javac] required: boolean [javac]
customerCodeEnabled = (boolean)
pageContext.findAttribute("customerCodeEnabled"); [javac] ^ [javac] 2
errors '



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


Re: html:text - want to set disable= to a bean value

Posted by Stuart Guthrie <sf...@eurekait.com>.
Thanks Rick.

I need to rely on the backend to decide whether to enable/disable as the
requirement is a 'business rule' not an interface decision. Here are the
factors:

- What 'stage' is this row of the table reached determines if this field
can be changed or not.
- What 'security level' the current session's user has determines
enable/disable.

So unfortunately, putting all this in the view would lead to huge
amounts of choosings. I'd rather the view was really dumb and just
reacted to decisions @ the backend.


> Then you can do:
> <html-el:text property="customerCode" maxlength="8"size="8"
> disable="${userFormBean.customerCodeEnabled}"  />

This looks promising. Thanks for your help..



Stuart


On Tue, 2004-08-17 at 01:24, Rick Reumann wrote:
> Stuart Guthrie wrote:
> 
> > Hi there, 
> > 
> > What I'm trying to do is re-use the same jsp for ADD/UPDATE modes. In
> > order to do this, certain field attributes will be different depending
> > on the modes and sometimes even on the user's security credentials or
> > the 'status' of the customer row.
> > 
> > To this end I need to pass in the form bean whether a particular field
> > is disabled or not
> 
> I usually don't like to have my formBean take care of holding this 
> information. Not that it's necessarily bad, I just sort of like having 
> my form beans as dumb as possible and only maintain form captured 
> information.
> 
> What I do in the above is base what to display on a "userAction" which 
> actually ends up corresponding to my dispatch Action method name. This I 
> will sometimes add as an ActionForm property (ie String userAction ).
> 
> I then control the dispaly based on this userAction ( "update", "add"). 
> You'll end up with a bit more verbose code but I find it easier to 
> maintain.. so for example....
> 
> You might have a case where if you are doing an update you can't update 
> the User Name but can update other fields:
> 
> Name:
> <c:choose>
>    <c:when test="${userFormBean.userAction == 'update'}">
>       <c:out value="${userFormBean.name}"/>
>    </c:when>
>    <c:othewise>
>       <html:text property="name"/>
>    </c:otherwise>
> </c:choose>
> 
> If you really want you can do your approach though but you'll have to 
> use the html-el tags
> 
> Then you can do:
> <html-el:text property="customerCode" maxlength="8"size="8"
> disable="${userFormBean.customerCodeEnabled}"  />
> 
> where customerCodeEnabled would correspond to "true" or "false" and be 
> set accordingly. I don't like this approach though because you'll end up 
> having to code a bunch of these for different fields and you've made 
> your backend responsible for figuring out how to display the info on the 
> page ( he he I say I don't like this, and now I'm on a project where the 
> whole application is going to be coded by meta-data to tell the front 
> what to display.. but still in theory I don't like it:)
> 


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


Re: html:text - want to set disable= to a bean value

Posted by Rick Reumann <st...@reumann.net>.
Stuart Guthrie wrote:

> Hi there, 
> 
> What I'm trying to do is re-use the same jsp for ADD/UPDATE modes. In
> order to do this, certain field attributes will be different depending
> on the modes and sometimes even on the user's security credentials or
> the 'status' of the customer row.
> 
> To this end I need to pass in the form bean whether a particular field
> is disabled or not

I usually don't like to have my formBean take care of holding this 
information. Not that it's necessarily bad, I just sort of like having 
my form beans as dumb as possible and only maintain form captured 
information.

What I do in the above is base what to display on a "userAction" which 
actually ends up corresponding to my dispatch Action method name. This I 
will sometimes add as an ActionForm property (ie String userAction ).

I then control the dispaly based on this userAction ( "update", "add"). 
You'll end up with a bit more verbose code but I find it easier to 
maintain.. so for example....

You might have a case where if you are doing an update you can't update 
the User Name but can update other fields:

Name:
<c:choose>
   <c:when test="${userFormBean.userAction == 'update'}">
      <c:out value="${userFormBean.name}"/>
   </c:when>
   <c:othewise>
      <html:text property="name"/>
   </c:otherwise>
</c:choose>

If you really want you can do your approach though but you'll have to 
use the html-el tags

Then you can do:
<html-el:text property="customerCode" maxlength="8"size="8"
disable="${userFormBean.customerCodeEnabled}"  />

where customerCodeEnabled would correspond to "true" or "false" and be 
set accordingly. I don't like this approach though because you'll end up 
having to code a bunch of these for different fields and you've made 
your backend responsible for figuring out how to display the info on the 
page ( he he I say I don't like this, and now I'm on a project where the 
whole application is going to be coded by meta-data to tell the front 
what to display.. but still in theory I don't like it:)


-- 
Rick

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


Re: html:text - want to set disable= to a bean value

Posted by Stuart Guthrie <sf...@eurekait.com>.
Thank you Susan, that looks spot on. I'll try it this AM..

ATB

Stuart

On Tue, 2004-08-17 at 01:09, Susan Bradeen wrote:
> Stuart Guthrie <sf...@eurekait.com> wrote on 08/16/2004 10:01:49 AM:
> 
> > Hi there, 
> > 
> > What I'm trying to do is re-use the same jsp for ADD/UPDATE modes. In
> > order to do this, certain field attributes will be different depending
> > on the modes and sometimes even on the user's security credentials or
> > the 'status' of the customer row.
> > 
> > To this end I need to pass in the form bean whether a particular field
> > is disabled or not
> > 
> > I've searched the archives to no avail. I'm trying to set the disable=''
> > attribute on the html:text tag to a value in the form bean I'm passing
> > in.
> > 
> > eg:
> > 
> > formbean.isCustomerCodeEnabled()
> > 
> > returns a boolean true/false
> > 
> > formbean.getCustomerCode()
> > 
> > is the value of customer code.
> > 
> > I'm trying (hoping) to do something like this:
> > 
> > <html:text property="customerCode" maxlength="8"size="8" 
> > disable="!CustomerCodeEnabled"  />
> > 
> > I've tried lots of different approaches, all failing. I've also scanned
> > the examples to no avail.
> > 
> > Latest attempt is:
> > 
> > <bean:define id="customerCodeEnabled"
> > name="CustomerFormWindowMainTabActionForm"
> > property="CustomerCodeEnabled"
> >     type="boolean" value="true"/>
> > 
> > <% boolean customerCodeDisabled=(!customerCodeEnabled); %>
> > <TD><html:text property="customerCode" maxlength="8"size="8" 
> > disabled="<%=customerCodeDisabled%>"  /></TD>
> 
> Does this work for you?
> <html:text property="customerCode" maxlength="8" size="8" 
> disable="isCustomerCodeEnabled" />
> 
> I had an app with similar requirements. IIRC, I solved it by doing the 
> following.
> 
> In the JSP first define the FormBean that contains the boolean values:
> <bean:define name="SomeForm" id="form" 
> type="com.myCompany.MyFormBeanClass" />
> 
> then access the boolean fields for each form field like so:
> <html:text property="description" maxlength="79" size="60" readonly="<%= 
> form.isDescriptionDisabled() %>" />
> 
> Hope that helps.
> Susan Bradeen
> 
> 
> > 
> > Which fails with:
> > 
> > customerCodeEnabled = null; [javac] ^ An error occurred at line: 87 in
> > the jsp file: /CustomerFormWindowMainTabBody.jsp Generated servlet
> > error:
> > [javac]/home/sfg/javadev/jboss-3.2.
> > 
> 3/server/default/work/MainEngine/localhost/pimsweb/CustomerFormWindowMainTabBody_jsp.
> > java:175: inconvertible types 
> > [javac] found : java.lang.Object [javac] required: boolean [javac]
> > customerCodeEnabled = (boolean)
> > pageContext.findAttribute("customerCodeEnabled"); [javac] ^ [javac] 2
> > errors '
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> > 
> > 
> > 
> _____________________________________________________________________________
> > Scanned for SoftLanding Systems, Inc. by IBM Email Security 
> > Management Services powered by MessageLabs. 
> > 
> _____________________________________________________________________________
> 
> 
> _____________________________________________________________________________
> Scanned for SoftLanding Systems, Inc. by IBM Email Security Management Services powered by MessageLabs. 
> _____________________________________________________________________________
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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


Re: html:text - want to set disable= to a bean value

Posted by Susan Bradeen <Su...@softlanding.com>.
Stuart Guthrie <sf...@eurekait.com> wrote on 08/16/2004 10:01:49 AM:

> Hi there, 
> 
> What I'm trying to do is re-use the same jsp for ADD/UPDATE modes. In
> order to do this, certain field attributes will be different depending
> on the modes and sometimes even on the user's security credentials or
> the 'status' of the customer row.
> 
> To this end I need to pass in the form bean whether a particular field
> is disabled or not
> 
> I've searched the archives to no avail. I'm trying to set the disable=''
> attribute on the html:text tag to a value in the form bean I'm passing
> in.
> 
> eg:
> 
> formbean.isCustomerCodeEnabled()
> 
> returns a boolean true/false
> 
> formbean.getCustomerCode()
> 
> is the value of customer code.
> 
> I'm trying (hoping) to do something like this:
> 
> <html:text property="customerCode" maxlength="8"size="8" 
> disable="!CustomerCodeEnabled"  />
> 
> I've tried lots of different approaches, all failing. I've also scanned
> the examples to no avail.
> 
> Latest attempt is:
> 
> <bean:define id="customerCodeEnabled"
> name="CustomerFormWindowMainTabActionForm"
> property="CustomerCodeEnabled"
>     type="boolean" value="true"/>
> 
> <% boolean customerCodeDisabled=(!customerCodeEnabled); %>
> <TD><html:text property="customerCode" maxlength="8"size="8" 
> disabled="<%=customerCodeDisabled%>"  /></TD>

Does this work for you?
<html:text property="customerCode" maxlength="8" size="8" 
disable="isCustomerCodeEnabled" />

I had an app with similar requirements. IIRC, I solved it by doing the 
following.

In the JSP first define the FormBean that contains the boolean values:
<bean:define name="SomeForm" id="form" 
type="com.myCompany.MyFormBeanClass" />

then access the boolean fields for each form field like so:
<html:text property="description" maxlength="79" size="60" readonly="<%= 
form.isDescriptionDisabled() %>" />

Hope that helps.
Susan Bradeen


> 
> Which fails with:
> 
> customerCodeEnabled = null; [javac] ^ An error occurred at line: 87 in
> the jsp file: /CustomerFormWindowMainTabBody.jsp Generated servlet
> error:
> [javac]/home/sfg/javadev/jboss-3.2.
> 
3/server/default/work/MainEngine/localhost/pimsweb/CustomerFormWindowMainTabBody_jsp.
> java:175: inconvertible types 
> [javac] found : java.lang.Object [javac] required: boolean [javac]
> customerCodeEnabled = (boolean)
> pageContext.findAttribute("customerCodeEnabled"); [javac] ^ [javac] 2
> errors '
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
_____________________________________________________________________________
> Scanned for SoftLanding Systems, Inc. by IBM Email Security 
> Management Services powered by MessageLabs. 
> 
_____________________________________________________________________________


_____________________________________________________________________________
Scanned for SoftLanding Systems, Inc. by IBM Email Security Management Services powered by MessageLabs. 
_____________________________________________________________________________

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