Struts - getting NPE when passing parameters to bean property - struts

I have a bean property in my form as follows (rates is a HashMap from FleetRateTypeCO to FleetRate[]):
public FleetRate[] getRatesByType(int typeID) {
return this.rates.get(FleetRateTypeCO.getByID(typeID));
}
Then in my jsp I want to do the following:
<c:when test="${not empty DedicatedFleetContractAdminForm.ratesByType[1]}">
...
</c:when>
But I get a null pointer exception:
java.lang.NullPointerException
at javax.el.BeanELResolver$BeanProperty.read(BeanELResolver.java:259)
at javax.el.BeanELResolver$BeanProperty.access$000(BeanELResolver.java:209)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:60)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
at org.apache.el.parser.AstValue.getValue(AstValue.java:97)
at org.apache.el.parser.AstEmpty.getValue(AstEmpty.java:29)
But what really confuses me is that if I try the following, it works fine:
<logic:iterate property="ratesByType[1]" name="DedicatedFleetContractAdminForm" id="overheadRates">
...
</logic:iterate>
Why would they work differently? Any help is appreciated - thank you in advance.

In one you are using the struts tags, and in the other EL.
Try using the struts tag

Related

Aurelia Binding errors ( on browser console)

I am using below snippet in html
value.two-way="lstName.IsBlocked ? 'Blocked' : Value2 + ' %'"
on console it shows error as
Uncaught Error: Binding expression
"lstName.IsBlocked?'Blocked':Value2+' %'" cannot be assigned to.
at b.a.assign (aurelia.js?v=1.0009:59)
at a.updateSource (aurelia.js?v=1.0009:61)
at a.call (aurelia.js?v=1.0009:61)
at a.v [as callSubscribers] (aurelia.js?v=1.0009:58)
at a.notify (aurelia.js?v=1.0009:60) `
What can be the reason for this ?
Thanks in advance!
Since you're using a two-way binding, the binding expression needs to be assignable.
As the error says: "lstName.IsBlocked?'Blocked':Value2+' %'" cannot be assigned to.. If your bound property changes from the view, it would have to be able to write back to the expression and update the source value in your view model. You can't really write to an inline if.
Change two-way to to-view and it should work.
EDIT:
Since you need the expression to be writable, you could use a ValueConverter to solve the problem (assuming Value2 is what you want to write to):
export class BlockedValueConverter {
toView(value, isBlocked) {
return isBlocked ? 'Blocked' : value + ' %';
}
fromView(value) {
return value;
}
}
Then in your html (don't forget to require the valueConverter or use globalResources):
value.two-way="Value2 | blocked:lstName.IsBlocked"

Assign a value to an attribute of a Microsoft.TeamFoundation.Build.Common.BuildParameter object using XAML

my BuildParameter is defined in my xaml build as follows:
<Activity this:Process.AdvancedBuildSettings=
"[New Microsoft.TeamFoundation.Build.Common.BuildParameter(
" { ""Attribute1"": """",
""Attribute2"": ""Value2"",
""Attribute3"": ""Value3"" } "
)]">
Now I want to update the value of Attribute1 of my BuildParameter but I can't figure out how to do it.
It doesn't look like I can use an Assign block because these attributes names are not known by the compiler, so I want to use BuildParameter's SetValue method but I'm not sure how to call this VB code in my xaml.
<Assign DisplayName="Update That Attribute">
<Assign.To>
<OutArgument x:TypeArguments="x:String">[AdvancedBuildSettings.Attribute1]</OutArgument><!-- this throws a compiler error because it doesn't know what Attribute1 is -->
</Assign.To>
<Assign.Value>
<InArgument x:TypeArguments="x:String">""NewValue""</InArgument>
</Assign.Value>
</Assign>
Not familiar with XAML, but here is a code snippet that using TFS API in C# to update the parameter name. You can use WorkflowHelpers.DeserializeProcessParameters Method and WorkflowHelpers.SerializeProcessParameters Method to get parameter name, remove it, and add the new parameter name, maybe it can help you something:
string argumentName = "Attribute1";
var process = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(BuildDefinition.ProcessParameters);
if (process.ContainsKey(argumentName))
{
process.Remove(argumentName);
process.Add(argumentName, attributeValue);
BuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
BuildDefinition.Save();
}
I was right, the "Assign" workflow tool was not the tool I wanted. I needed to use the "InvokeMethod" workflow tool in order to invoke the SetValue() method of my BuildParameter object in my XAML build.
MSDN InvokeMethod documentation
More details about the properties of InvokeMethod
So my solution looks like this:
<InvokeMethod DisplayName="Invoke That Method" MethodName="SetValue">
<InvokeMethod.GenericTypeArguments>
<x:Type Type="x:String" />
</InvokeMethod.GenericTypeArguments>
<InvokeMethod.TargetObject>
<InArgument x:TypeArguments="mtbc:BuildParameter">[AdvancedBuildSettings]</InArgument>
</InvokeMethod.TargetObject>
<InArgument x:TypeArguments="x:String">Attribute1</InArgument>
<InArgument x:TypeArguments="x:String">[NewValue]</InArgument>
</InvokeMethod>

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper

I am using ASP.NET MVC 4 and I have 2 insert queries in 2 partial views.
in other view call 2 action. But I get this error
Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper
error in:
#Html.Action("InsertState", "Foundation")
When I continue, the error does not show any error in my page and the insert query works correctly, but this error is showing before this.
No issue in using ViewBag even if you are taking values from database. Also, create a View Model composed of all your required models and then pass the main model from controller and in view use this main model
Model:
public class MainModel
{
public ModelA objModelA {get;set;}
public ModelB objModelB {get;set;}
public ModelC objModelC {get;set;}
}
Controller:
Public ActionResult ActionName()
{
ViewBag.state=new SelectList()fdgfg);
return View(new MainModel());
}
View:
#model MainModel
#Html.TextBoxFor(x=>x.ModelA.age)
#Html.TextBoxFor(x=>x.ModelA.name)
#Html.Dropdown("state")
Your question is not very clear. Check the Exception Message. This might have occurred due to some error in View.
This error could also arise if you have an error in your partial view. I encountered this situation when i was using a partial view in main view. i had this on the partial view
<img id="image54tr" alt="Image De l'Immobilier" src="" "/>
with one more quote in the img tag and when trying to compile, get the similar error. By removing this quote and having the below tag, the problem was solved
<img id="image3im" alt="Image De l'Immobilier" src="" />
This mean that when you have this type of error, first inspect your partialview to see if there is not any error before looking for another ways to solve it

Translation of Zend_Validation in ZF2

I have a strange Problem in Zend Framework 2. I've used the Zend Skeleton Application (https://github.com/zendframework/ZendSkeletonApplication) and added PhlyContact as Vendor Module (https://github.com/weierophinney/PhlyContact). I changed the Translation-Type to PhpArray so that i can use the Zend_Validate.php located in the resources-dir of the ZF2-Dist.
Everything translates EXCEPT the validation Messages :/ So i guess i am missing something:
I must pass the Translator to Zend_Validate (but how and where?)
The Translation should use a Text-Domain, but doesn't
When i remember right in ZF1 you had to set the Translator to default to pass it to Zend_Validate. Any Ideas on that !?
have a look at these methods
\Zend\Validator\AbstractValidator::setDefaultTranslator();
\Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain();
You can even do this with only one line (2nd parameter is text domain):
AbstractValidator::setDefaultTranslator($translator, 'default');
Example within Module.php:
use Zend\Validator\AbstractValidator;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$translator = ....
AbstractValidator::setDefaultTranslator($translator, 'default');
}
}

Upload file in Stripes, how to use DefaultMultipartWrapperFactory

I'm trying to develop a small Stripes project that allows the user to uoload files, the basic implementation of the ActionBean looks like so:
public class UploadActionBean extends BaseActionBean{
private FileBean fileBean;
private final String fileUpload="/WEB-INF/jsp/file-upload.jsp";
public void setFileBean(FileBean fileBean){
this.fileBean=fileBean;
}
public FileBean getFileBean(){
return this.fileBean;
}
#DefaultHandler
public Resolution goToFile(){
return new ForwardResolution(fileUpload);
}
public Resolution upload() throws IOException{
System.out.println(fileBean.getFileName());
fileBean.getContentType();
fileBean.getSize();
fileBean.save(new File("/Users/enricoiorio/Desktop"));
return new ForwardResolution(fileUpload);
}
}
As i said is very simple, the jsp is like this, also very simple:
<s:form beanclass="stripesbook.action.UploadActionBean" enctype="multipart-form/data">
<s:file name="fileBean"/>
<s:submit name="upload" value="upload"/>
The app seems to deploy correctly, the app starts with no problem but as soon as i click on upload i get the following exception:
net.sourceforge.stripes.exception.StripesRuntimeException: Could not construct a MultipartWrapper for the current request.
which arrives from a nullPointerException:
at net.sourceforge.stripes.controller.multipart.DefaultMultipartWrapperFactory.wrap(DefaultMultipartWrapperFactory.java:151)
I understand that i have to use the wrap() method of the DefaultMultipartWrapperFactory class, but how?
I'm struggling trying to find a documentation that explains that but no results, any advise?
Seems like you're simply missing Commons FileUpload. Try adding it to your classpath and see if it works.
I had got the same problem.
Got resolved by adding init param in stripes Filters.
<init-param>
<param-name>MultipartWrapper.Class</param-name>
<param-value>net.sourceforge.stripes.controller.multipart.CommonsMultipartWrapper</param-value>
</init-param>