How to extend Zend_Form prefix path while configuring form through XML (Zend_Config) to load custom form elements? - zend-framework

I'm loading my Zend_Form from an XML file :
<form>
<elements>
<role>
<type>MyProject_Form_Element_Select_Roles</type>
<options>
<label>Role:</label>
<value></value>
</options>
</role>
<valid>
<type>submit</type>
<options>
<label>Valid</label>
</options>
</valid>
</elements>
</form>
Of course the XML below doesn't work since Zend doesn't know how to load my custom field (which is just an extension of Zend_Form_Element_Select), but the line below doesn't work, if anyone can help :
<form>
<elementPrefixPath>
<prefix>MyProject_Form_Element_Select</prefix>
<path>MyProject/Form/Element/Select</path>
<type>element</type>
</elementPrefixPath>
...
I found these config features really cool but finding info or tutorial on them is really tough (I know there's some mapping rule between the Zend_Form objects structure and the expected config file, but I do never found a complete description of it if someone has a link)

Here's the correct form XML description :
<form>
<prefixPath>
<element>
<prefix>MyProject_Form_Element_Select</prefix>
<path>MyProject/Form/Element/Select</path>
</element>
</prefixPath>
<prefixPath>
<element>
<prefix>MyLib_Form_Element_Select</prefix>
<path>MyLib/Form/Element/Select</path>
</element>
</prefixPath>
<elements>
<role>
<type>Roles</type>
<options>
<label>Role:</label>
<value></value>
</options>
</role>
<valid>
<type>submit</type>
<options>
<mycustomoption></mycustomoption>
<label>Valid</label>
</options>
</valid>
</elements>
</form>
The custom options will be send inside the $options argument of the constructor of your Element
class MyProject_Form_Element_Select_Roles extends Zend_Form_Element_Select
{
public function __construct($spec, $options = null) {
//don't forget to call parent !
//$options is a Zend_Config that should have as a member mycustomptions
}
}

Related

how to edit single row in rich:dataTable

i have to edit a row in a table using rich faces 4 and modal panel. I am new one so please tell me in details and i know to make a table in rich faces. i already searched so many things but not getting any fruitful
See answer for question "Richfaces: show details in popup [commandbutton, action and popupPanel]". It works in RichFaces 4.x with rowClick.
Or here is example with commandLink:
<a4j:commandLink action="#{actionBean.setupTransactionDetails}"
event="onclick" render="transactionDetails"
oncomplete="#{rich:component('transactionDetails')}.show()"
styleClass="rich-link">
<h:outputText value="#{res.transactionType}" />
<f:setPropertyActionListener value="#{res.transactionId}"
target="#{profile.transactionId}" />
</a4j:commandLink>
But I prefer updated version like this:
<a4j:jsFunction name="showDetail" action="#{actionBean.setupTransactionDetails}"
oncomplete="#{rich:component('transactionDetails')}.show();"
render="transactionDetails">
<a4j:param name="id" assignTo="#{profile.transactionId}"
converter="javax.faces.Long" />
</a4j:jsFunction>
<rich:dataTable id="txnTable" rows="#{referenceData.recordsPerPage}"
style="width: 100%" rowClasses="oddrow, evenrow"
value="#{profile.transactions}" var="res" sortMode="single">
<h:column width="110">
<f:facet name="header">
<h:outputText value="#{msg.transactionType}" />
</f:facet>
<a4j:commandLink onclick="showDetail('#{res.transactionId}');"
value="#{res.transactionType}" />
</h:column>
</rich:dataTable>
<rich:popupPanel id="transactionDetails" autosized="true"
style="max-height:600px;">
<!-- f:facet name="header" and f:facet name="controls" here -->
<h:form id="transactionDetailsForm">
<!-- some details here -->
</h:form>
</rich:popupPanel>
Profile backing bean
private Long transactionId; // + getter and setter
Action backing bean
public void setupTransactionDetails() {
Transaction txn = DAO.getInstance().get(Transaction.class, getProfile().getTransactionId());
transactionForm.setup(txn);
}
In case if you use EL 2.2 (or higher) you can call action bean method with parameter.

How to change magento's cms content wrapper

I am using magento 1.7. i have tried to change wrapper of cms content but still i cannot get how i can change wrapper of cms_page.
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>std</value></action>
<block type="cms/page" name="cms_page"/>
</block>
and html output is
<div class="std">
CMS Page content
</div>
but i want to output like this
<section class="std">
CMS Page Content
</section>
Please give me any solution
You can try following code for change div to section
<block type="page/html_wrapper" name="cms.wrapper" translate="label">
<label>CMS Content Wrapper</label>
<action method="setElementClass"><value>std</value></action>
<action method="setAttribute"><param1>html_tag_name</param1><param2>section</param2></action>
<block type="cms/page" name="cms_page"/>
</block>
this will change div to section because html_wrapper class get tag name from a function getElementTagName in app\code\core\Mage\Core\Block\Abstract\Wrapper.php
/**
* Wrapper element tag name getter
* #return string
*/
public function getElementTagName()
{
$tagName = $this->_getData('html_tag_name');
return $tagName ? $tagName : 'div';
}
so by calling setAttribute we change/set value of html_tag_name

how to populate a drop down(<s:select) in struts2 from json response

i am unable to populate my Struts2 select drop down in my jsp page.
Note: My jsp page loads through json response.
I have a select box inside a form. But i don't t know how to populate it when my jsp page loads.
And in the same page i have a select dropdown in my Struts2 jquery grid,which i am able to populage but i don't know how to populate a drop down for my form which are out side of the grid.
Please help me regarding this issue.
my jsp page
<s:url id="selecturl" action="selectaction"/>
<s:url id="bookediturl" action="bookeditt"/>
<s:url id="bookremoteurl" action="booksetups"/>
<sjg:grid
id="bookgrid"
formIds="form2"
reloadTopics="reloadMyGrid"
caption="List of Cover Details"
dataType="json"
href="%{bookremoteurl}"
pager="true"
gridModel="gridModel"
rowList="50,100,5000"
rowNum="20"
filter="true"
filterOptions="{stringResult :false,searchOnEnter : false,enableClear : true,gridModel : true}"
rownumbers="true"
editurl="%{bookediturl}"
navigator="true"
editinline="true"
navigatorSearch="false"
autowidth="false"
width= "1550"
viewrecords="true"
navigatorRefresh="true"
navigatorDelete="true">
<sjg:gridColumn name="id" index="locationId" title="ID" formatter="integer" sortable="false" key="true"
search="false" editable="true" hidden="true" />
<sjg:gridColumn name="authLastname" index="authLastname" title="AuthorLastname" sortable="true" search="true" editrules="{required: true}"
editable="true" edittype="text" />
<sjg:gridColumn name="subjectId" title="Subject Name" editable="true" sortable="false" align="center" search="false" searchtype="select"
searchoptions="{dataUrl:'%{selecturl}'}" edittype="select" editoptions="{dataUrl:'%{selecturl}'}" />
</sjg:grid>
<div id="myDivBox" style="display:none; width :300px;position: relative;top: -30px;left: 299px;button:0px;">
<s:form action="searchkeywordss" id="form2" theme="simple" cssClass="yform">
<sj:textfield placeholder="Enter keyword to search" cssClass="txtbox" size="42" maxLength="255" name="keywordsearch"/>
<sj:select href="%{selecturl}" name="countryselect" list="%{lstsub}" listKey="id" listValue="subjectName" theme="jquery" cssStyle="margin-top:4px;"/>
<sj:a button="true" id="btnid" cssStyle="position: relative;top: 0px;left: 09px;" onClickTopics="reloadMyGrid">Find</sj:a>
</s:form>
</div>
struts.xml
<action name="booksetups" class="v.esoft.actions.bookdetails.BookdetailsAction" >
<result name="success" type="json"/>
<result name="login" type="redirect"> /index.jsp </result>
</action>
<action name="selectaction" class="v.esoft.actions.bookdetails.SelectAction">
<result name="success">/select.jsp</result>
</action>
You should only use the sj:select like below
<sj:select href="%{selecturl}" name="countryselect" list="subjectList" listKey="id" listValue="subjectName" theme="jquery" cssStyle="margin-top:4px;"/>
where selecturl returns a json response, subjectList is name of list in the json reponse which contains the options
Your selectaction should have a json response, but what you have now is an action returning a jsp so it would not work. If you cannot change it, you should create another action which returns json.

How do I use form beans in Spring MVC?

I'm new to Spring MVC (3.1.1). Coming from a Rails and Struts1 world that is.
In Struts, our FormBeans automatically map to our controllers. For example:
# JS file
ExtJS.ajax({action:'update', value:42});
Then our controller can:
bean.getAction(); // 'update'
bean.getValue(); // 42
We instantiate the bean like:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyBean bean = (MyBean) form;
....
}
Please forgive my ignorance, but how would I do the same thing in Spring MVC?
In jsp do something like this :
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<form:form name="frmFoo" id="frmFoo" action="/FormSubmitUrl" method="POST" modelAttribute="foo">
<form:select path="myField">
<form:errors path="myField" />
</form:form>
And just add the backing object to the model in your controller method :
#RequestMapping(value = "/MyFooForm", method = RequestMethod.GET)
public String getFoo(final Model model)
{
model.addAttribute("foo", foo);
return "fooForm.jsp";
}
Am going from, Spring MVC - Rails. I like Rails lot better :-). There are lot of start up tutorials for Spring MVC. But spring has a good tutorial that you can follow. But to begin with you will have to start with the spring-dispatch-servlet.xml. There you will define your association between views, controller and form. For example in this following snippet:
<bean name="/priceincrease.htm" class="springapp.web.PriceIncreaseFormController">
<property name="sessionForm" value="true"/>
<property name="commandName" value="priceIncrease"/>
<property name="commandClass" value="springapp.service.PriceIncrease"/>
<property name="validator">
<bean class="springapp.service.PriceIncreaseValidator"/>
</property>
<property name="formView" value="priceincrease"/>
<property name="successView" value="hello.htm"/>
<property name="productManager" ref="productManager"/>
</bean
Controller is the PriceIncreaseFormController and the priceIncrease is the equivalent command object. The corresponding view i.e. JSP will have
<form:form method="post" commandName="priceIncrease">
<table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
<tr>
<td align="right" width="20%">Increase (%):</td>
<td width="20%">
<form:input path="percentage"/>
</td>
<td width="60%">
<form:errors path="percentage" cssClass="error"/>
</td>
</tr>
</table>
But I think you might get a complete picture from this place where I picked up the code from
http://static.springsource.org/docs/Spring-MVC-step-by-step/part4.html#step4.5 and the place where you can get Spring MVC's example code base is https://src.springframework.org/svn/spring-samples/mvc-basic
I was looking for this answer today based on some code in a project I inherited. What I found was that the if you create a controller action on a multiActionController. The form values can be mapped to a bean that would be the third paarameter on your handler action.
In my case I had a controller like this
public void submit(HttpServletRequest request,
HttpServletResponse response, SomeBean sb) {
{
//do something with sb - SomeBean
}
My issue was in figuring out how the values in my form were mapped to the controller action. There was no reference at all to the SomeBean within my jsp form. As it turns out Spring works the magic based on the controller action parameters and the names used in the form. It basically maps the values in the form to a bean that is used as the third parameter in the action method.
For example my SomeBean has some fields named byday and bymonth. It also has the corresponding byday and bymonth setters and getters (i.e. getBymonth(), setBymonth). In my for my submit action is mapped on submit and I have input values for byday and by month like so:
<select id="weekly_option" name="byday">
<option value="MON">Monday</option>
<option value="TUE">Tuesday</option>
<option value="WED">Wednesday</option>
<option value="THU">Thursday</option>
<option value="FRI">Friday</option>
<option value="SAT">Saturday</option>
<option value="SUN">Sunday</option>
</select>
I had to do some digging on how exactly the mappings were being done. I peeked into the MultiActionController source code to see that if does the following:
The controller figures out if you have a third parameter in your action (it must not be of the type HttpSession).
The MultiActionController then news up an instance of the third parameter (SomeBean). Based on the http request values it pushes over all the values from the HttpServleRequest over to the SomeBean object.
At this point it seems like it only works with properties that are strings. I imagine that you would have to extend MVC somehow if you wanted to work with properties other than strings within your bean.

giving errors in bootstrap when try to use breadcrumbs in zend framework

hi i want to use a breadcrumb for my zend framework application
i craeted navigation.xml in configs folder where application.ini is .
and in the bootstarp i added following code
protected function _initNavigation()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION_PATH.'/configs/navigation.xml');
$navigation = new Zend_Navigation($config);
$view->navigation($navigation);
}
and in the layout i added folllowing code
<div id="menu">
<?php echo $this->navigation()->menu(); ?>
</div>
<div id="breadcrumbs">
You are in: <?php echo $this->navigation()->breadcrumbs()->setLinkLast(false)->setMinDepth(0)->render(); ?>
</div>
it is not working , errors are given
Fatal error: Uncaught exception 'Zend_Navigation_Exception' with message 'Invalid argument: Unable to determine class to instantiate' in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php:223
Stack trace:
#0 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(117): Zend_Navigation_Page::factory(Array)
#1 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Container.php(164): Zend_Navigation_Container->addPage(Array)
#2 /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation.php(46): Zend_Navigation_Container->addPages(Object(Zend_Config_Xml))
#3 /home/kanishka/workspace/jetwing_ibe/application/Bootstrap.php(94): Zend_Navigation->__construct(Object(Zend_Config_Xml))
#4 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initNavigation()
#5 /home/kanishka/workspace/jetwing_ibe/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('navigati in /home/kanishka/workspace/jetwing_ibe/library/Zend/Navigation/Page.php on line 223
this is my xml file
<?xml version="1.0" encoding="UTF-8"?>
<config>
<nav>
<dashboard>
<label>dashboard</label>
<controller>dashboard</controller>
<action>index</action>
<resource>dashboard</resource>
<pages>
<rates>
<label>Rates</label>
<controller>rates</controller>
<action>index</action>
<pages>
<index>
<label>index</label>
<controller>rates</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
</pages>
</rates>
<occupancydenomination>
<label>Occupancydenominations</label>
<controller>occupancydenomination</controller>
<action>index</action>
<pages>
<index>
<label>Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>index</action>
<class>dontdisplay</class>
</index>
<add>
<label>Add Occupancydenomination</label>
<controller>occupancydenomination</controller>
<action>add</action>
<class>dontdisplay</class>
</add>
</pages>
</occupancydenomination>
</pages>
</dashboard>
</nav>
</config>
i am not sure what the error is . please help me ................
The error is due to your config file.
You're not providing enough parameters for the navigation container to determine the correct page type, Zend_Navigation_Page_Mvc or Zend_Navigation_Page_Uri.
Also, you know there's a navigation resource plugin, right?
UPDATE
Get rid of the <nav> wrapper element. It's trying to interpret that as a page.
That or do follow the example and specify the config section correctly
$config = new Zend_Config_Xml('/path/to/navigation.xml', 'nav');
$container = new Zend_Navigation($config);