You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sr...@chennai.tcs.co.in on 2003/10/22 07:18:49 UTC

Display Mode | Edit Mode

Does STRUTS provide any feature so that the same jsp can be used for
showing the page in Display Mode as well as Edit Mode without having to
manually code the same in JSP ?

Regards
Sreekant G
@ 98404-65630



Re: Display Mode | Edit Mode

Posted by Ted Husted <hu...@apache.org>.
sreekant_gottimukkala@chennai.tcs.co.in wrote:
 > Does STRUTS provide any feature so that the same jsp can be used for
 > showing the page in Display Mode as well as Edit Mode without having
 > to manually code the same in JSP ?

The bundled Struts taglibs do not have a display mode property, but the 
Struts Layout tags do:

http://struts.application-servers.com/

Another very good taglib is DisplayTag

http://displaytag.sourceforge.net/

DisplayTag is not Struts-specific, but it sure is pretty :)

-Ted.


-- 
Ted Husted,
   Junit in Action  - <http://www.manning.com/massol/>,
   Struts in Action - <http://husted.com/struts/book.html>,
   JSP Site Design  - <http://www.amazon.com/exec/obidos/ISBN=1861005512>.



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


RE: Display Mode | Edit Mode

Posted by Wiebe de Jong <wi...@shaw.ca>.
Or you could have multiple mappings pointing to one action and one jsp.

Each mapping would set a different value for the parameter, the action would
use the parameter to set some beans, and the jsp would use the beans to
control the output.

As in the following code:

----------

struts-config.xml:

<!-- Execute the Item Add action -->
<action path="/itemAdd"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="add"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>

<!-- Execute the Item Change action -->
<action path="/itemChange"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="change"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>

<!-- Execute the Item Inspect action -->
<action path="/itemInspect"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="inspect"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>
		    
<!-- Execute the Item Delete action -->
<action    path="/itemDelete"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="delete"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>
		    
----------

ItemLoadAction.java:

String action = mapping.getParameter();

// set ACID properties
if ("add".equals(action))
  session.setAttribute("mode.form", "add");
if ("change".equals(action))
  session.setAttribute("mode.form", "change");
if ("inspect".equals(action))
  session.setAttribute("mode.form", "inspect");
if ("delete".equals(action))
  session.setAttribute("mode.form", "delete");

// set view properties
if ("delete".equals(action) || "inspect".equals(action))
  session.setAttribute("mode.fields", "read");
else
  session.setAttribute("mode.fields", "update");

----------

item.jsp:

<tr>
  <td><bean:message key="item.date"/></td>
  <td align="left">
    <logic:equal name="mode.fields" value="read">
      <html:text property="date" disabled="true" maxlength = "8" size =
"8"/>
    </logic:equal>
    <logic:equal name="mode.fields" value="update">
      <html:text property="date" maxlength = "8" size = "8"/>
    </logic:equal>
  </td>
</tr>

<tr><td align="right">
  <logic:equal name="mode.form" value="add">
    <html:submit> <bean:message key="button.add"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="change">
    <html:submit> <bean:message key="button.update"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="delete">
    <bean:message key="warning.delete"/>&nbsp;&nbsp;
    <html:submit> <bean:message key="button.delete"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="inspect">
    <html:submit> <bean:message key="button.ok"/> </html:submit>
  </logic:equal>
</td></tr>

------------

-----Original Message-----
From: Marc Dugger [mailto:marc@socotech.com] 
Sent: Wednesday, October 22, 2003 4:48 AM
To: Struts Users Mailing List
Subject: RE: Display Mode | Edit Mode

It's not so much a feature as the way you design your Action and ActionForm.
I do this with all JSP responsible for creating/editing some persistent
business object.  What I do:

1.  Create two actions named Get[YourBusinessObject]Action and
Edit[YourBusinessObject]Action.  Both should extends DispatchAction.
2.  Create two mappings in your struts-config:  /yourbizobj/get and
/yourbizobject/edit.  Set 'validate' to true on /yourbizobject/edit and
define a 'parameter' attribute on each action mapping (i.e.
parameter="mode").
3.  Create a form-bean entry in struts-config with the necessary properties.
4.  Implement two methods in each Action:  add and update.  The 'add' on
Get[YourBusinessObject]Action is called to do any initialization before
return a blank form to the user (i.e. /yourbizobject/get?mode=add).  The
'update' on Get[YourBusinessObject]Action is used to retrieve the business
object from persistent storage and populate the ActionForm with property
values (i.e. /yourbizobject/get?mode=update).  The 'add' on
Edit[YourBusinessObject]Action is used to insert a new business object into
persistent storage (i.e. /yourbizobject/edit?mode=add) while the 'update'
used to update an already existing business object in persistent storage
(i.e. /yourbizobject/get?mode=update).


> -----Original Message-----
> From: sreekant_gottimukkala@chennai.tcs.co.in
> [mailto:sreekant_gottimukkala@chennai.tcs.co.in]
> Sent: Wednesday, October 22, 2003 12:19 AM
> To: struts-user@jakarta.apache.org
> Subject: Display Mode | Edit Mode
>
>
> Does STRUTS provide any feature so that the same jsp can be used for
> showing the page in Display Mode as well as Edit Mode without having to
> manually code the same in JSP ?
>
> Regards
> Sreekant G
> @ 98404-65630
>
>
>


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


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


RE: Display Mode | Edit Mode

Posted by Marc Dugger <ma...@socotech.com>.
It's not so much a feature as the way you design your Action and ActionForm.
I do this with all JSP responsible for creating/editing some persistent
business object.  What I do:

1.  Create two actions named Get[YourBusinessObject]Action and
Edit[YourBusinessObject]Action.  Both should extends DispatchAction.
2.  Create two mappings in your struts-config:  /yourbizobj/get and
/yourbizobject/edit.  Set 'validate' to true on /yourbizobject/edit and
define a 'parameter' attribute on each action mapping (i.e.
parameter="mode").
3.  Create a form-bean entry in struts-config with the necessary properties.
4.  Implement two methods in each Action:  add and update.  The 'add' on
Get[YourBusinessObject]Action is called to do any initialization before
return a blank form to the user (i.e. /yourbizobject/get?mode=add).  The
'update' on Get[YourBusinessObject]Action is used to retrieve the business
object from persistent storage and populate the ActionForm with property
values (i.e. /yourbizobject/get?mode=update).  The 'add' on
Edit[YourBusinessObject]Action is used to insert a new business object into
persistent storage (i.e. /yourbizobject/edit?mode=add) while the 'update'
used to update an already existing business object in persistent storage
(i.e. /yourbizobject/get?mode=update).


> -----Original Message-----
> From: sreekant_gottimukkala@chennai.tcs.co.in
> [mailto:sreekant_gottimukkala@chennai.tcs.co.in]
> Sent: Wednesday, October 22, 2003 12:19 AM
> To: struts-user@jakarta.apache.org
> Subject: Display Mode | Edit Mode
>
>
> Does STRUTS provide any feature so that the same jsp can be used for
> showing the page in Display Mode as well as Edit Mode without having to
> manually code the same in JSP ?
>
> Regards
> Sreekant G
> @ 98404-65630
>
>
>


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


RE: Display Mode | Edit Mode

Posted by Navjot Singh <na...@net4india.net>.
NO

>-----Original Message-----
>From: sreekant_gottimukkala@chennai.tcs.co.in
>[mailto:sreekant_gottimukkala@chennai.tcs.co.in]
>Sent: Wednesday, October 22, 2003 10:49 AM
>To: struts-user@jakarta.apache.org
>Subject: Display Mode | Edit Mode
>
>
>Does STRUTS provide any feature so that the same jsp can be used for
>showing the page in Display Mode as well as Edit Mode without having to
>manually code the same in JSP ?
>
>Regards
>Sreekant G
>@ 98404-65630
>
>
>

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