Thinking that , in struts 1.2, say a function public ActionForward abc(){ return null;} will return to the same page.
But i got this exception.
java.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:441)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
How to get into the same page?
You can use
return mapping.getInputForward();
In struts-config.xml, write a forward tag inside your action tag like this.
<action ...>
<forward name = "samePage" path="..."/>
</action>
Now, in your code use
mapping.findForward("samePage");
Related
I have written a tag helper that I can use as follows...
<mytaghelper attr1="jim"></mytaghelper>
I would like to be able to shorten this to just...
<mytaghelper attr1="jim">
...or at least...
<mytaghelper attr1="jim"/>
However, I can't get this to work. Here is some sample code for the Process method...
public override void Process(TagHelperContext context, TagHelperOutput output) {
output.TagName = "div";
output.PreContent.SetHtmlContent("<div>");
output.Content.SetHtmlContent("OUTPUT HTML GOES HERE");
output.PostContent.SetHtmlContent("</div>");
output.Attributes.Clear();
}
I have tried adding a TagStructure setting to the HtmlTargetElement attribute on the class...
[HtmlTargetElement("mytaghelper", TagStructure = TagStructure.WithoutEndTag)]
...but it doesn't seem to make any difference. <mytaghelper attr1="jim"/> generates <div /> and <mytaghelper attr1="jim"></mytaghelper> generates <div></mytaghelper>.
If I set the TagStructure to NormalOrSelfClosing then included a closing tag works, but <mytaghelper attr1="jim"/> gives an empty <div />
Anyone able to explain what I need to do?
TagStructure.WithoutEndTag is able to write the tag with only a start tag or self-closing, but the output would be <div > or <div/> . Self-closing anchor tags are not valid HTML, so you wouldn't want to create one, but you might want to create a tag helper that's self-closing. Tag helpers set the type of the TagMode property after reading a tag. Add the below code line Inside the process method:
output.TagMode = TagMode.StartTagAndEndTag;
Take a moment to read Author Tag Helpers in ASP.NET Core which covers this perfectly .
The correct syntax is:
[HtmlTargetElement("mytaghelper", TagStructure = TagStructure.WithoutEndTag)]
Which should be applied to the taghelper class, not the Process method. You may already be doing that, but it wasn't clear in your question. I believe you still must use the self-closing tag syntax (/>) for it work, though.
I want to disable click when variable isAgree is false:
here code:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<variable
name="handler"
type="myproject.ui.SubscribeBrandDialogFragment" />
</data>
<TextView
android:id="#+id/subscribeTextView"
android:layout_width="185dp"
android:layout_height="40dp"
android:layout_marginTop="#dimen/default_margin"
android:background="#{handler.isAgree ? #drawable/border_enable_bg : #drawable/border_disable_bg}"
android:gravity="center"
android:onClick="#{handler.isAgree ? handler.onClickSubscribe() : null}"
android:textColor="#{handler.isAgree ? #color/color_primary : #color/disable_text_color}" />
</layout>
But I get error in android:onClick :
e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'android:onClick' with parameter type void on android.widget.TextView.
file:myproject\layout\subscribe_brand_dialog.xml
loc:100:31 - 100:81
****\ data binding error ****
at android.databinding.tool.processing.Scope.assertNoError(Scope.java:112)
at android.databinding.annotationprocessor.ProcessDataBinding.doProcess(ProcessDataBinding.java:101)
at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:65)
at org.jetbrains.kotlin.kapt3.ProcessorWrapper.process(annotationProcessing.kt:131)
I know that I can fix this by java code. But I want fix this ONLY in xml layout.
Use lambda expression.
android:onClick="#{() -> handler.isAgree ? handler.onClickSubscribe() : null}"
Well a couple things.
First, I would use the controls properties the way they are meant to be used. Setting null on the click handler does not appropriately handle the UI element, you are merely hacking.
You should be disabling the click property or focus property based on your boolean, rather then toggling click handlers to null.
Secondly typically when you are doing Terinaray statements in xml click events I have seen the handler::methodName used rather then handler.methodName to ensure it is handled property in the generated databinding classes for onClick.
Lastly, if you already have the agreed boolean, why not just handle the click in the code. You literally saved yourself 1 line for another line if you think about it.
myClick()
if(isAgree) . //you saved this
.
now you have to do this
ObservableBoolean<> myBool = new ObservableField()
myBool.set(true/false)
of you are adding the
#Bindable to a method.
Either way you are not really saving code by doing the boolean check in the xml and you lose your ability to unit test it or debug. Just my two cents.
I have this code in my JSP:
<%#taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
..
..
<html:form action="update" >
..
..
<html:submit value="delete" />
<html:submit value="edit" />
<html:sumit value="update" />
</html:form>
And this in the struts-config.xml file:
<action path="/delete" name="currentTimeForm" input="/viewall.jsp" type="com.action.DeleteProduct">
<forward name="success" path="/viewall.jsp" />
<forward name="failure" path="/viewall.jsp" />
</action>
Like the delete action, I have edit and update. It works fine, if I give the name specifically like <html:form action="delete"> but, how to make it dynamically work for update and edit?
You have one form and multiple submit buttons. The problems is that a form can only submit to one action, no matter how many submit buttons you have inside the form.
Three solutions come to mind right now:
1. Have just one action where you submit everything. Once inside the Action class check what button was used to submit the form and perform the appropriate treatment based on that.
<html:form action="modify">
..
..
<html:submit value="delete"/>
<html:submit value="edit" />
<html:sumit value="update" >
</html:form>
In the ModifyAction.execute(...) method have something like:
if (request.getParameter("delete") != null || request.getParameter("delete.x") != null) {
//... delete stuff
} else if (request.getParameter("edit") != null || request.getParameter("edit.x") != null) {
//...edit stuff
} else if (request.getParameter("update") != null || request.getParameter("update.x") != null) {
//... update stuff
}
2. Have the action attribute of the HTML form changed using JavaScript before submitting the form. You first change the submit buttons to plain ones with click handlers attached:
<html:form action="whatever">
..
..
<html:button value="delete" onclick="submitTheForm('delete.do')" />
<html:button value="edit" onclick="submitTheForm('edit.do')" />
<html:button value="update" onclick="submitTheForm('update.do')" />
</html:form>
With the handler:
function submitTheForm(theNewAction) {
var theForm = ... // get your form here, normally: document.forms[0]
theForm.action = theNewAction;
theForm.submit();
}
3. Use a DispatchAction (one Action class similar to point 1) but without the need to test for what button was clicked since that's treated by the DispatchAction.
You just provide three execute methods properly named delete, edit and update. Here is an example that explains how you might do it.
In conclusion: For number 1, I don't really like those ugly tests.... for number 2, I don't really like the fact that you have to play with the action form using JavaScript, so I would personally go for number 3.
There is another simpler way to do this as follows:
In the ActionForm currentTimeForm, add a String property (example: buttonClicked).
In the jsp, in each of the html:submit tags add this property.
Now in the action execute method simply check the value of this property, ie.
if(currentTimeForm.getButtonClicked().equals("delete"){
}
else if((currentTimeForm.getButtonClicked().equals("edit"))
and so on...
Can I give a XBL handler a name, so I can call it from my javascript like I do with XBL methods?
It seems not, but you can create an XBL Method and call it from both your handler and other JavaScript. Something like:
<handler event="mouseover">
this.handleMouseOver();
</handler>
...
<method name="handleMouseOver">
<body>...
//and in javascript code:
yourObj.handleMouseOver();
From a XBL method, when I need to call another method, I do like:
<method name="myMethod_1">
<body>
<![CDATA[
// do staff
]]>
</body>
</method>
<method name="myMethod_2">
<body>
<![CDATA[
document.getElementById("thisElementID").myMethod_1();
]]>
</body>
</method>
I would like to know if is there a way to call the local method without need the element id? I've tried this.myMethod_1() but it says the method don't exist.
In the specific case of an event listener, there is another way around the problem, and that is to pass the element itself as the listener. Of course you only get one handleEvent method, so this is less useful if you're listening to lots of different events on lots of different event targets.
<implementation implements="nsIDOMEventListener">
<method name="handleEvent">
<parameter name="aEvent"/>
<body>
<![CDATA[
// do stuff
]]>
</body>
</method>
can you show us code calling myMethod_2? If you call it like: document.getElement(...).myMethod_2() that's fine, but if you have something like someElement.addEventHandler("click", myxbl.myMethod_2,...); that won't work since event target will be this.
This is important for determining what is this in that context
EDIT: (Tom's reply)
ow, think I got it.. it's exactly this the problem.. I'm calling it from a keypress listener of another document, and the "this" was not what I think..